﻿using MediatR;
using SlaughterItem.Common.Domains.Warehouse;
using SlaughterItem.Common.Dtos;
using SlaughterItem.Common.Infrastructures.Interfaces;
using SlaughterItem.Enum;

namespace GetSlaughterItem.API.Application.Commands.Week02.Warehouse
{
    /// <summary>
    /// 获取仓库分类表数据
    /// </summary>
    public class GetDepotTypesHandler : IRequestHandler<GetDepotTypeCommand, Result>
    {
        public IBaseRepositoryGet<DepotType> DepotTypeRepositoryGet { get; set; }
        public GetDepotTypesHandler(IBaseRepositoryGet<DepotType> depotTypeRepositoryGet)
        {
            DepotTypeRepositoryGet = depotTypeRepositoryGet;
        }
        public async Task<Result> Handle(GetDepotTypeCommand request, CancellationToken cancellationToken)
        {
            var result = new Result() { Code=(int)CommonErrorCode.Search};
            var list = DepotTypeRepositoryGet.GetAll().ToList();
            if (list != null)
            {
                result.Data = list;
                result.Code = (int)CommonErrorCode.Success;
                return result;
            }
            else
            { 
                return result;
            }
        }
    }
}
